
package com.zcp.wizard;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class MyTabActivity extends TabActivity implements Constants {

    private TabHost m_tabHost;

    public static int index = 0;// 当时0的时候 system放前面

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab);

        // getTabHost返回的TabHost用于装载tabs
        m_tabHost = getTabHost();
        Intent intent;
        TabSpec spec;
        // 添加系统清理界面
        intent = new Intent();
        intent.setClass(this, SystemClearActivity.class);
        spec = getTabSpec("system", R.layout.tabhost_indicator_system, intent);

        Intent batteryIntent;
        TabSpec batterySpec;
        // 添加电池管理界面
        batteryIntent = new Intent();
        batteryIntent.setClass(this, BatteryManagerActivity.class);
        batterySpec = getTabSpec("battery", R.layout.tabhost_indicator_battery, batteryIntent);

        // 由于tab页中只有一张背景图片，没有文字就没有办法点击测试，所以设置这样的
        if (index == 0) {
            m_tabHost.addTab(spec);
            m_tabHost.addTab(batterySpec);
        } else {
            m_tabHost.addTab(batterySpec);
            m_tabHost.addTab(spec);
        }

        MyBroadcastReceiver.register(this);

        Intent myintent = this.getIntent();
        if (myintent != null) {
            String value = myintent.getAction();

            if ("battery".equals(value)) {
                m_tabHost.setCurrentTab(1);
            }else if("system".equals(value)){
                m_tabHost.setCurrentTab(0);
            }
        }
    }
    
    public TabSpec getTabSpec(String name, int layoutId, Intent content) {

        LayoutInflater mInflater = getLayoutInflater();
        TabSpec spec = m_tabHost.newTabSpec(name);
        View view = mInflater.inflate(layoutId, null);
        spec.setIndicator(view);
        spec.setContent(content);
        return spec;
    }

    @Override
    public void onDestroy() {
        if(m_tabHost!=null)
        {
        m_tabHost.removeAllViews();
        }
        m_tabHost=null;
        MyBroadcastReceiver.unRegister(this);
        super.onDestroy();
    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    @Override
    protected void onPause() {

        super.onPause();
    }

  

}
